package com.facemox.controller;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.facemox.bean.FaceInfo;
import com.facemox.service.FaceInfoService;

@RestController
public class FaceInfoController {
    
    @Autowired
    private FaceInfoService faceInfoService;
   
    @Autowired
    private FaceInfo faceInfo;
    
    @RequestMapping("/add_interface")
    public String add(HttpServletRequest request) {
        String faceName = request.getParameter("face_name");
        String faceMethod = request.getParameter("face_method");
        String faceProtocol = request.getParameter("face_protocol");
        String faceBody = request.getParameter("face_body");
        String faceHost = request.getParameter("face_host");
        String faceUrl = request.getParameter("face_url");
        String tempMID = request.getParameter("module_id");
        Integer moduleId = Integer.valueOf(tempMID);
        String tempAuthID = request.getParameter("authentication_id");
        Integer authenticationId = Integer.valueOf(tempAuthID);

        faceInfo.setFaceName(faceName);
        faceInfo.setFaceMethod(faceMethod);
        faceInfo.setFaceProtocol(faceProtocol);
        faceInfo.setFaceBody(faceBody);
        faceInfo.setFaceHost(faceHost);
        faceInfo.setFaceUrl(faceUrl);
        faceInfo.setModuleId(moduleId);
        faceInfo.setAuthenticationId(authenticationId);
        int effectLine = faceInfoService.addInterface(faceInfo);
        return effectLine+"@"+moduleId;
    }
    
    
    @RequestMapping("delete_face_by_face_id")
    public int deleteFaceByFaceId(HttpServletRequest request) {
        String tempFID = request.getParameter("faceId");
        Integer faceId = Integer.valueOf(tempFID);
        int effectLine = faceInfoService.deleteFaceByFaceId(faceId);
        return effectLine;
    }
}
